<html>
<head>
</head>
<body>
<div class="page-container">
    <div class="page-content">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet light bordered">
                        <div class="portlet-title">
                            <div class="caption">
                              <span class="caption-subject font-green-sharp bold uppercase">
                              <i class="fa fa-gift"></i> 添加客户
                              </span>
                            </div>
                        </div>
                        <div class="portlet-body form">
                            <form action="javascript:;" id="updateForm" class="form-horizontal">
                                <div class="form-body">
                                    <div class="row">
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">客户名称：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <div class="input-icon right">
                                                        <i class="fa"></i>
                                                        <input class="form-control" type="text" id="customerName"
                                                               placeholder="请输入客户名称" name="customerName" >
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">客户类别：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <div class="input-icon right">
                                                        <select class="hasReward form-control" name="type"
                                                                id="type" >
                                                            <option value="">请选择</option>
                                                            <option value="1">组织客户</option>
                                                            <option value="2">个人客户</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12" id="nameHid" hidden>
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">联系人姓名：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <input class="form-control" type="text" id="contact"
                                                           placeholder="请输入联系人姓名" name="contact" >
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">性别：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <select class="hasReward form-control" name="sex"
                                                            id="sex" >
                                                        <option value="">请选择</option>
                                                        <option value="M">男</option>
                                                        <option value="W">女</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">年龄：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <input class="form-control" type="text" id="age"
                                                           placeholder="请输入年龄" name="age" >
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                                            <div class="form-group">
                                                <label class="col-md-2 col-sm-4 col-xs-4 control-label">联系电话：</label>
                                                <div class="col-md-8 col-sm-8 col-xs-8">
                                                    <input class="form-control" type="text" id="telephone"
                                                           placeholder="请输入联系电话" name="telephone" >
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="form-group">
                                            <label class="col-md-2 col-sm-2 col-xs-2 control-label">联系地址：</label>
                                            <div class="col-md-10 col-sm-10 col-xs-10">
                                                <input class="form-control" type="text" id="address"
                                                       placeholder="请输入联系地址" name="address" >
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="text-right">
                                            <button type="button" class="btn green"
                                                    onclick="doAdd()">确认添加
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    jQuery(document).ready(function () {
        $("#type").change(nameShow);
    });
    function nameShow() {
        if ($("#type").val()==1){
            $("#nameHid").show();
        }else if ($("#type").val()==2){
            $("#nameHid").hide();
            $("#contact").val($("#customerName").val());
        }
    }
    function doAdd() {
        if ($("#customerName").val()==''||$("#customerName").val()==null){
            layer.msg("请输入客户姓名！");return;
        }
        if ($("#type").val()==''||$("#type").val()==null){
            layer.msg("请选择客户类别！");return;
        }
        if ($("#contact").val()==''||$("#contact").val()==null){
            layer.msg("请输入联系人姓名！");return;
        }
        if ($("#sex").val()==''||$("#sex").val()==null){
            layer.msg("请选择性别！");return;
        }
        if ($("#age").val()==''||$("#age").val()==null){
            layer.msg("请输入年龄！");return;
        }
        if ($("#telephone").val()==''||$("#telephone").val()==null){
            layer.msg("请输入联系电话！");return;
        }
        if ($("#address").val()==''||$("#address").val()==null){
            layer.msg("请输入联系地址！");return;
        }
        showMode();
        $.ajax({
            type: "POST",
            data: $('#updateForm').serializeArray(),
            url: rootPath + "/customerCon/ajax/addCustomer",
            dataType: 'json',
            success: function (data, textStatus) {
                if (data.code == '0000') {
                    parent.commonJs.alertMsg(data.msg, function () {
                        closeWindow();
                        closeMode();
                    });
                } else {
                    commonJs.alertMsg(data.msg, function () {
                        closeMode();
                    });
                }
            }
        });
    }
    function closeWindow(){
        window.parent.selectList();
        window.parent.layer.closeAll();
    }
</script>
</body>
</html>